package smartlifev30.com.sdk.api.gateway_app;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import java.util.ArrayList;
import java.util.List;

import smartlifev30.com.sdk.util.JsonUtil;
import smartlifev30.com.sdk.api.CallBack;
import smartlifev30.com.sdk.api.ConstantGateway;
import smartlifev30.com.sdk.bean.request.AddLinkageRequest;
import smartlifev30.com.sdk.bean.request.QueryLinkRequest;
import smartlifev30.com.sdk.bean.response.LinkageQueryResponse;
import smartlifev30.com.sdk.bean.response.LoginResponse;
import smartlifev30.com.sdk.net.baiwei.NetManager;
import smartlifev30.com.sdk.net.baiwei.ResponseHelper;

/**
 * Created by tys on 2018/8/14.
 */

public class LinkAgeMgmtGatewayImpl implements ILinkAgemgmtGateway {

    @Override
    public void queryLinkage(@NonNull String userName, @NonNull String token, @NonNull String sn,
                             @Nullable List<Integer> linkageId, @NonNull CallBack<LinkageQueryResponse> callBack) {
        QueryLinkRequest queryLinkRequest = new QueryLinkRequest();
        queryLinkRequest.setFrom(userName);
        queryLinkRequest.setTo(sn);
        queryLinkRequest.setMsg_id(callBack.getMsgId());
        queryLinkRequest.setMsg_class(ConstantGateway.MSG_CLASS_LINKAGE);
        queryLinkRequest.setMsg_name("linkage_query");
        queryLinkRequest.setMsg_type(ConstantGateway.MSG_TYPE_GET);
        queryLinkRequest.setToken(token);
        List<QueryLinkRequest.LinkageList> list = null;
        if (linkageId != null) {
            list = new ArrayList<>();
            for (Integer id : linkageId) {
                list.add(queryLinkRequest.new LinkageList(id));
            }
        }
        queryLinkRequest.setLinkage_list(list);
        NetManager.getInstance().sendMessage(JsonUtil.toString(queryLinkRequest));
        ResponseHelper.addListen(callBack);
    }

    @Override
    public void addLinkage(@NonNull String userName, @NonNull String token, @NonNull String sn,
                           @NonNull AddLinkageRequest.Linkage linkage, @NonNull CallBack<LoginResponse> callBack) {

    }

}
